package com.itheima.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.itheima.mapper.PmsMemberPriceMapper;
import com.itheima.pojo.PmsMemberPrice;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@DubboService
public class PmsMemberPriceImpl implements PmsMemberPriceApi {

    @Autowired
    private PmsMemberPriceMapper mapper;

    /**
     *商品添加
     */
    @Override
    public void save(List<PmsMemberPrice> memberPriceList, Long productId) {
        for (PmsMemberPrice pmsMemberPrice : memberPriceList) {
            pmsMemberPrice.setProductId(productId);
            mapper.insert(pmsMemberPrice);
        }
    }

    /**
     *根据商品id获取商品编辑信息
     */
    @Override
    public List<PmsMemberPrice> updateInfo(Integer productId) {
        LambdaQueryWrapper<PmsMemberPrice> lqw = new LambdaQueryWrapper<>();
        lqw.eq(PmsMemberPrice::getProductId,productId);
        List<PmsMemberPrice> pmsMemberPrices = mapper.selectList(lqw);
        return pmsMemberPrices;
    }

    /**
     *更新商品
     */
    @Override
    public void updateProduct(List<PmsMemberPrice> memberPriceList, Long productId) {
        for (PmsMemberPrice pmsMemberPrice : memberPriceList) {
            pmsMemberPrice.setProductId(productId);
            mapper.updateById(pmsMemberPrice);
        }
    }
}
